<template>
  <div>
    <van-nav-bar title="账户资料"
                 left-text=""
                 left-arrow
                 @click-left="onClickLeft"/>
    <div class="vanCell">

      <van-uploader :after-read="onRead" :accept="'image/*'">
        <van-cell title="个人头像"
                  is-link
        ></van-cell>

        <div class="posImg posImgVant">
          <img :src="`${imgUrl}${imgStr}`"/>
        </div>
      </van-uploader>

      <van-cell title="账号"
                :value="UserInfo.userid"/>
      <van-cell title="性别"
                :value="UserInfo.sex"
      />
      <van-cell title="电话号码"
                :value="UserInfo.mobile"/>
      <van-cell title="邮箱地址"
                :value="UserInfo.email"/>
      <van-cell title="个人身份"
                :value="UserInfo.status"/>
      <van-cell v-if="com_certify===0 || per_certify=== 0"
                title="实名认证"
                is-link
                @click='goAutonym'/>
      <van-cell title="信用数值"
                is-link
                @click="goCreditNum"/>
      <div class="posImg CreditNumImg">
        <img :src="imgUrl1"
             alt="" width="100%" height="100%">
      </div>
      <van-cell title="安全设置"
                is-link
                @click='goSetPwd'/>
    </div>
  </div>
</template>

<script>
  import {setStore, getStore} from '@/config/mUtils'

  export default {
    name: "accountdata",
    data() {
      return {
        UserInfo: {},
        hierarchyNum: 0,
        imgUrl: 'http://www.menpuwang.com/',
        com_certify: '',
        per_certify: '',
        logo: '',
        prelogo: '',
        imgStr: '/attachment/face/202001/1577934396pllgi.png'
      }
    },
    computed: {
      imgUrl1() {
        return require(`../../../static/credit/${this.hierarchyNum}.gif`)
      }
    },
    methods: {
      initDate() {
        let params = this.qs.stringify({
          "token": getStore('token')
        })
        this.$axios.post('user/info', params).then((res) => {
          this.UserInfo = res.data.data
          this.hierarchyNum = res.data.data.credits
          this.logo = res.data.data.logo
          this.prelogo = res.data.data.prelogo
          this.com_certify = res.data.data.com_certify
          this.per_certify = res.data.data.per_certify
          if ( res.data.data.logo !== '' ) {
            this.imgStr = res.data.data.logo
          }
          setStore("if_corp", res.data.data.if_corp)
        })
      },
      onRead(file) {
        let _this = this
        this.$axios.post("user/avatar", this.qs.stringify({
              token: getStore('token'),
              logo: _this.logo,
              prelogo: _this.prelogo,
              img: file.content
            })
        ).then(res => {
          if ( res.data.status == 1 ) {
            this.$toast.success(res.data.message);
            console.log(res.data);
            _this.initDate()
          } else {
            this.$toast.fail(res.data.message);
          }
        });
      },
      updateImg(str) {
        this.$axios.post("user/avatar", this.qs.stringify({
              token: getStore('token'),
              logo: str,
              prelogo: str,
              img: str
            })
        ).then(res => {
          if ( res.data.status == 1 ) {
            // this.str = res.data.
            // this.$toast.success(res.data.message);
          } else {
            // this.$toast.fail(res.data.message);
          }
        });
      },
      onClickLeft() {
        this.$router.go(-1)
      },
      goSetPwd() {
        this.$router.push('/setPsd')
      },
      goAutonym() {
        this.$router.push('/autonym')
      },
      goCreditNum() {
        this.$router.push('/CreditNum')
      }
    },
    created() {
      this.initDate()
    },
  }
</script>

<style lang="scss" scoped>
  @import "../../../static/css/user/user.scss";

  .CreditNumImg img {
    width: auto;
    height: auto;
    margin-top: 25px;
  }

  .posImgVant {
    position: absolute !important;
    right: 0px !important;
    top: 100px !important;
  }

  /deep/ .van-uploader__input-wrapper, .van-uploader {
    width: 100%;
  }
</style>
